package net.esj.basic.utils;


public class JavaProtoTypeHelper {

	public static boolean equal(Object o1,Object o2){
		if(o1.getClass()!=o2.getClass()){
			return false;
		}
		if(o1 instanceof String ){
			return ((String)o1).equals((String)o2);
		}
		if( o1.getClass() == int.class
				|| o1.getClass() == float.class
				|| o1.getClass() == double.class
				|| o1.getClass() == short.class
				|| o1.getClass() == long.class
				|| o1.getClass() == byte.class
				|| o1.getClass() == char.class
				|| o1.getClass() == boolean.class){
			return o1==o2;
		}
		if(o1 instanceof Number ){
			return ((Number)o1).doubleValue() == ((Number)o2).doubleValue();
		}
		if(o1 instanceof Character ){
			return o1.toString().equals(o2.toString());
		}
		return o1==o2;
	}
	
	public static final Object valueOf(String str,Class clazz){
		if(int.class == clazz || Integer.TYPE == clazz){
			return Integer.valueOf(str);
		}else if(byte.class == clazz || Byte.TYPE == clazz){
			return Byte.valueOf(str);
		}else if(boolean.class == clazz || Boolean.TYPE == clazz){
			return Boolean.valueOf(str);
		}else if(float.class == clazz || Float.TYPE == clazz){
			return Float.valueOf(str);
		}else if(double.class == clazz || Double.TYPE == clazz){
			return Double.valueOf(str);
		}else if(char.class == clazz || Character.TYPE == clazz){
			return str.charAt(0);
		}else if(long.class == clazz || Long.TYPE == clazz){
			return Long.valueOf(str);
		}
		return str;
	}
}
